home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 …ember: Reference Library / Dev.CD Dec 00 RL Disk 1.toast / mac / Technical Documentation / Develop / develop Issue 24 / develop Issue 24 code / Scriptable Database 1.0a15.sea / Scriptable Database 1.0a15 / Blue / EventHandlerTable.cp / EventHandlerTable.cp
Encoding:
Text File  |  1996-02-20  |  2.9 KB  |  92 lines  |  [TEXT/CWIE]

  1.  
  2. #include "EventHandlerTable.h"
  3.  
  4. //========================================================================================
  5. // CLASS TEventHandlerTable
  6. //========================================================================================
  7.  
  8. #include <Events.h>
  9.  
  10. //----------------------------------------------------------------------------------------
  11. // TEventHandlerTable::TEventHandlerTable
  12. //----------------------------------------------------------------------------------------
  13. TEventHandlerTable::TEventHandlerTable()
  14.     {
  15.     }
  16.  
  17. //----------------------------------------------------------------------------------------
  18. // TEventHandlerTable::~TEventHandlerTable
  19. //----------------------------------------------------------------------------------------
  20. TEventHandlerTable::~TEventHandlerTable()
  21.     {
  22.     }
  23.  
  24. //----------------------------------------------------------------------------------------
  25. // TEventHandlerTable::InstallHandler
  26. //----------------------------------------------------------------------------------------
  27. OSStatus TEventHandlerTable::InstallHandler(AEEventClass handlerClass, AEEventID handlerID, EventHandlerProcPtr handler, UInt32 handlerRefcon)
  28.     {
  29.     OSStatus err = noErr;
  30.  
  31. #if GENERATINGCFM
  32.     
  33.     //
  34.     // In this case we should only call InstallHandler once per handler that
  35.     // we wish to install, so we'll just go ahead and leak memory like crazy
  36.     // (it's not really a memory leak, as we want eventHandlerRD to stick
  37.     // around until the application quits, at which time it will be freed
  38.     // up along with the rest of the application's resources.
  39.     //
  40.     AEEventHandlerUPP eventHandlerRD = NewRoutineDescriptor((ProcPtr) handler, uppAEEventHandlerProcInfo, GetCurrentISA());
  41.     err = AEInstallEventHandler(handlerClass, handlerID, eventHandlerRD, handlerRefcon, false);
  42.     
  43. #else
  44.     
  45.     //
  46.     // In this case, an EventHandlerProcPtr should be the same as a AEEventHandlerUPP,
  47.     // so we won't bother to typecast
  48.     //
  49.     err = AEInstallEventHandler(handlerClass, handlerID, handler, handlerRefcon, false);
  50.  
  51. #endif
  52.     
  53.     return err;
  54.     }
  55.  
  56. //----------------------------------------------------------------------------------------
  57. // TEventHandlerTable::Receive
  58. //----------------------------------------------------------------------------------------
  59. OSStatus TEventHandlerTable::Receive(AEReceiveMode receiveMode, long maxSleepTime)
  60.     {
  61.     OSStatus err = noErr;
  62.     Boolean receiving = true;
  63.     
  64.     while(receiving)
  65.         {
  66.         EventRecord event;
  67.         WaitNextEvent(everyEvent, &event, maxSleepTime, nil);
  68.             
  69.         switch(event.what)
  70.             {
  71.             //
  72.             // We live for high level events (and not much else)
  73.             //
  74.             case kHighLevelEvent:
  75.                 {
  76.                 //
  77.                 // We've installed the Futures package,
  78.                 // so any call to AEProcessAppleEvent
  79.                 // will spawn a thread to process the event
  80.                 //
  81.                 err = AEProcessAppleEvent(&event);
  82.                 if((receiveMode == kAEReceiveOneEvent) || ((receiveMode == kAEReceiveUntilUnhandledEvent) && (err == errAEEventNotHandled)))
  83.                     receiving = false;
  84.                 break;
  85.                 }
  86.             }
  87.         }
  88.     
  89.     return err;
  90.     }
  91.  
  92.